<template>
  <ul>
    <li v-for="(item, i) in productsStore.all" :key="i">
      {{ item.title }} - {{ item.price }}
      <br />
      <button
        :disabled="!item.inventory"
        @click="cartStore.addProducToCart(item)"
      >
        添加到购物车
      </button>
    </li>
  </ul>
</template>

<script lang="ts" setup>
import {} from "vue";
import { useProductsStore } from "../store/products";
import { useCartStore } from "../store/cart";

const productsStore = useProductsStore();
const cartStore = useCartStore();

// 加载所有数据
productsStore.loadAllProducts();
</script>

<style lang="less" scoped></style>
